package com.lu.pojo.functionInterface;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author luzhenfang
 * @date 2020 07 13
 * @description 断言接口
 */
public class Perd {
    public static void main(String[] args) {
        // 满足条件字符串放入集合中
        List<String> strings = Arrays.asList("Buffer","List","apple","a","b","c");
        // 过滤长度>3的单词
        List<String> list = filterStr(strings, s -> s.length() > 3);
        list.forEach(System.out::println);
    }
    public static List<String> filterStr(List<String> list, Predicate<String>pre){
        List<String> strings = new ArrayList<>();
        for (String s : list) {
            if (pre.test(s)) {
                strings.add(s);
            }
        }
        return strings;
    }
}
